import request from '/@/utils/request';
import other from '/@/utils/other';
import { AxiosResponse } from 'axios';
import { ISysAttendanceShiftGroup, ISysAttendanceShiftGroupView, ISysAttendanceShiftGroupVm } from '/@/views/hr/sysattendanceshiftgroup/api/interface';

interface ISysAttendanceShiftGroupApi {

  search(data: object): Promise<AxiosResponse<ISysAttendanceShiftGroupView[]>>;
  get(id: string | number): Promise<AxiosResponse<ISysAttendanceShiftGroupVm>>;
  add(data: ISysAttendanceShiftGroupVm): Promise<AxiosResponse<ISysAttendanceShiftGroup>>;
  edit(data: ISysAttendanceShiftGroupVm): Promise<AxiosResponse<ISysAttendanceShiftGroup>>;
  batchEdit(data: object): Promise<AxiosResponse>;
  delete(ids: (string | number)[]): Promise<AxiosResponse<number>>;
  export(data: object): Promise<void>;
  exportById(ids: (string | number)[]): Promise<void>;
  import(data: object): Promise<AxiosResponse<number>>;
  approve(data: object, tag: string): Promise<AxiosResponse<any, any>>;
  getShiftItems(): Promise<AxiosResponse<ISysAttendanceShiftGroupView[]>>;
}

function SysAttendanceShiftGroupApi(): ISysAttendanceShiftGroupApi {
  return {

    async search(data: object): Promise<AxiosResponse<ISysAttendanceShiftGroupView[]>> {
      return await request({
        url: '/api/SysAttendanceShiftGroup/Search',
        method: 'post',
        data,
      });
    },
    async get(id: string | number): Promise<AxiosResponse<ISysAttendanceShiftGroupVm>> {
      return await request({
        url: `/api/SysAttendanceShiftGroup/${id}`,
        method: 'get',
      });
    },
    async add(data: ISysAttendanceShiftGroupVm): Promise<AxiosResponse<ISysAttendanceShiftGroup>> {
      return await request({
        url: '/api/SysAttendanceShiftGroup/Add',
        method: 'post',
        data,
      });
    },
    async edit(data: ISysAttendanceShiftGroupVm): Promise<AxiosResponse<ISysAttendanceShiftGroup>> {
      return await request({
        url: '/api/SysAttendanceShiftGroup/Edit',
        method: 'put',
        data,
      });
    },
    async batchEdit(data: object): Promise<AxiosResponse> {
      return await request({
        url: '/api/SysAttendanceShiftGroup/batchEdit',
        method: 'post',
        data,
      });
    },
    async delete(ids: (string | number)[]): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysAttendanceShiftGroup/BatchDelete',
        method: 'post',
        data: ids,
      });
    },
    async export(data: object): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysAttendanceShiftGroup/ExportExcel',
        method: 'post',
        data,
      });
      other.downloadFile(response);
    },
    async exportById(ids: (string | number)[]): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysAttendanceShiftGroup/ExportExcelByIds',
        method: 'post',
        data: ids,
      });
      other.downloadFile(response);
    },
    async import(data: object): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysAttendanceShiftGroup/Import',
        method: 'post',
        data,
      });
    },
    async approve(data: object, tag: string) {
      return request({
        url: '/api/SysAttendanceShiftGroup/approve?tag=' + tag,
        method: 'post',
        data,
      });
    },
    // 获取班次列表
    async getShiftItems(): Promise<AxiosResponse<ISysAttendanceShiftGroupView[]>> {
      return await request({
        url: '/api/SysAttendanceShiftGroup/GetShifTitems',
        method: 'get',

      });
    },
  }
}

export { SysAttendanceShiftGroupApi };